<script setup lang="ts">
import { ref, toRefs, reactive, onMounted, watch } from 'vue';
import ArrowVue from '@/components/icon/Arrow.vue';
import ScrollVue from '@/components/Scroll.vue';
const ScrollDom = ref()
const props = defineProps({
  list: {
    type: Array,
    default: [] as Array<Record<string, any>>
  },
})
const { list } = toRefs(props)
const state = reactive({
  list: [] as any,
})
const handleClick = (index: number) => {
  ScrollDom.value.clickFn(index)
}
onMounted(() => {
  state.list = list.value
})
watch(list, (val: any) => {
  state.list = val
})
</script>

<template>
  <div class="business-wrapper">
    <div class="container">
      <div style="height: 500px" class="business-inner">
        <ScrollVue :list="state.list" :show-num="3" :margin="20" :pagination="false" ref="ScrollDom">
          <template v-for="(item, index) in state.list" #[index]>
            <router-link class="business-item" :class="[index % 2 === 0 ? 'odd' : 'even']"
              :to="'/content/imgcase?id=' + item.id">
              <div class="inner">
                <div class="img-wrap">
                  <div class="img">
                    <img :src="item.cover_url" :alt="item.title">
                  </div>
                </div>
                <div class="info">
                  <div class="title font-m text-main line-1">{{ item.title }}</div>
                  <div class="desc font line-2">{{ item.introduce }}</div>
                </div>
              </div>
              <div class="arrow">
                <ArrowVue class="span" color="#9195A3"></ArrowVue>
              </div>
            </router-link>
          </template>
        </ScrollVue>
        <div class="business-arrow left" @click="handleClick(-1)"></div>
        <div class="business-arrow right" @click="handleClick(1)"></div>
      </div>
    </div>
  </div>
</template>

<style lang="scss">
.business {
  &-wrapper {
    overflow: hidden;
    position: relative;
    height: 640px;
    padding-top: 90px;
    background: #F0F0F0;

    &::before {
      content: '';
      position: absolute;
      top: 320px;
      width: 100%;
      height: 1px;
      background: #C6C6C6;
    }
  }

  &-inner {
    position: relative;
    padding: 0 55px;
  }

  &-list {
    overflow: hidden;
  }

  &-arrow {
    position: absolute;
    top: 230px;
    width: 34px;
    height: 34px;
    background-color: rgba($color: #fff, $alpha: 0.6);
    transform: translateY(-17px);
    cursor: pointer;

    &.left {
      left: -5px;

      &::after {
        border-width: 0 0 1px 1px;
      }
    }

    &.right {
      right: -5px;

      &::after {
        border-width: 1px 1px 0 0;
      }
    }

    &::after {
      content: "";
      position: absolute;
      left: 50%;
      top: 50%;
      width: 8px;
      height: 8px;
      border: solid 1px #626675;
      transform: translate(-50%, -50%) rotate(45deg);
    }

    &:hover {
      background-color: rgba($color: #fff, $alpha: 0.9);
    }
  }

  &-item {
    position: relative;
    float: left;
    width: 430px;
    height: 380px;
    transition: all .3s ease-out 0s;
    cursor: pointer;

    &:not(:last-child) {
      margin-right: 20px;
    }

    &::before,
    &::after {
      content: '';
      position: absolute;
      transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;
      opacity: 0;
    }

    &::before {
      top: 10px;
      left: 200px;
      width: calc(100% - 400px);
      height: calc(100% - 24px);
      border-top: 2px solid #626675;
      border-bottom: 2px solid #626675;
    }

    &::after {
      left: 10px;
      top: 200px;
      width: calc(100% - 24px);
      height: calc(100% - 300px);
      border-left: 2px solid #626675;
      border-right: 2px solid #626675;
    }

    .inner {
      position: relative;
    }

    .img-wrap {
      z-index: 3;
      position: absolute;
      left: 0;
      width: 100%;
      height: 200px;
      transition: all 0.40s ease-in-out 0s;

      .img {
        position: absolute;
        left: 50%;
        top: 50%;
        width: 280px;
        height: 180px;
        transform: translate(-50%, -50%);

        img {
          width: 100%;
          height: 100%;
          object-fit:cover;
        }
      }
    }

    // &:nth-child(odd)
    &.odd {
      .inner {
        padding-top: 250px;
      }

      .img-wrap {
        top: 0;
      }
    }

    // &:nth-child(even)
    &.even {
      .inner {
        padding-bottom: 250px;
      }

      .img-wrap {
        bottom: -80px;
        top: auto;
      }
    }

    .info {
      z-index: 3;
      position: relative;
      padding: 40px 80px 0;
      text-align: center;
      transition: all .36s ease;

      .title {
        position: relative;
        padding-bottom: 15px;
        margin-bottom: 20px;

        &::after {
          content: '';
          position: absolute;
          left: 50%;
          bottom: 0;
          width: 28px;
          height: 1px;
          background-color: #9195A3;
          transform: translateX(-50%);
          transition: all 0.6s cubic-bezier(0.215, 0.61, 0.355, 1) 0s;
        }
      }

      .desc {
        color: #848484;
      }
    }

    .arrow {
      z-index: 3;
      position: absolute;
      left: 50%;
      bottom: 40px;
      transform: translateX(-50%);
      opacity: 0;
      transition: all .3s ease-out 0s;

      .span {
        position: absolute;
        top: -0;
        transition: all .3s ease-out 0s;
      }
    }


    &.odd:hover {
      .img-wrap {
        transform: translateY(-90%) rotateX(90deg);
        transform-origin: center bottom 0;
        opacity: 0;
      }

      .info {
        margin-top: -35%;
        transform: translateY(-10px);
      }
    }

    &.even:hover {
      .img-wrap {
        transform: translateY(90%) rotateX(-90deg);
        transform-origin: center top 0;
        opacity: 0;
      }

      .info {
        transform: translateY(102px);
      }
    }

    &:hover {
      background-color: #E6E6E6;

      &::before {
        left: 10px;
        width: calc(100% - 24px);
        z-index: 2;
        opacity: 1;
      }

      &::after {
        height: calc(100% - 24px);
        left: 10px;
        top: 10px;
        opacity: 1;
        background-color: #fff;
      }

      // &:nth-child(odd) {
      //   .img-wrap {
      //     transform: translateY(-90%) rotateX(90deg);
      //     transform-origin: center bottom 0;
      //     opacity: 0;
      //   }

      //   .info {
      //     margin-top: -35%;
      //     transform: translateY(-10px);
      //   }
      // }

      // &:nth-child(even) {
      //   .img-wrap {
      //     transform: translateY(90%) rotateX(-90deg);
      //     transform-origin: center top 0;
      //     opacity: 0;
      //   }

      //   .info {
      //     transform: translateY(102px);
      //   }
      // }

      .info {
        .title {
          &::after {
            width: 80px;
          }
        }
      }

      .arrow {
        opacity: 1;

        .span {
          position: absolute;
          top: -40px;
        }
      }
    }
  }
}
</style>
